/**版本V1.0.1 菜心虫 封装一些常用的JS操作*/

function tableSerialize(a) {
    return $("#" + a).serialize()
}
function ajaxPost(a, b, c) {
    $.ajax({
        url: a,
        type: "POST",
        data: b,
        dataType: "json",
        timeout: 3000,
        beforeSend: function (d) {
            d.setRequestHeader("Token", $.cookie("SYSTEMUSERID") == null ? null : $.cookie("SYSTEMUSERID"))
        },
        async: true,
        success: c(resp),
        error: errorFuction
    })
}
function errorFuction(a) {
    parent.layer.msg("异常错误,服务器异常")
}
function getParam(a) {
    var b = new RegExp("(^|&)" + a + "=([^&]*)(&|$)");
    var c = window.location.search.substr(1).match(b);
    if (c != null) {
        return unescape(c[2])
    }
    return null
}
function getRandomNum(c) {
    var b = "";
    for (var a = 0; a < c; a++) {
        b += Math.floor(Math.random() * 10)
    }
    return b
}
function init(c, a, b) {
    $("#" + c).bootstrapTable("destroy");
    $("#" + c).bootstrapTable({
        method: "GET",
        url: a,
        search: false,
        pagination: true,
        showRefresh: false,
        pageNumber: 1,
        pageSize: 10,
        clickToSelect: true,
        sidePagination: "server",
        pageList: [20, 40, 60, 80, 100],
        showColumns: true,
        iconSize: "outline",
        icons: {
            refresh: "glyphicon-repeat",
            columns: "glyphicon-list"
        },
        queryParams: function (e) {
            var d = null;
            if (b != null && b != "" && b != undefined) {
                d = $("#" + b).serializeJsonObject();
                d["limit"] = e.limit;
                d["pageNo"] = e.offset / e.limit + 1
            } else {
                d = {
                    "pageNo": (e.offset / e.limit) + 1,
                    "limit": e.limit
                }
            }
            return d
        },
        responseHandler: function (e) {
            var d = [];
            if (e != null && e != "" && typeof e != "undefined") {
                if (e.data != null && e.data != "" && typeof e.data != "undefined") {
                    if (e.data.total != null && e.data.total != "" && typeof e.data.total != "undefined") {
                        if (e.data.list != null && e.data.list != "" && typeof e.data.list != "undefined") {
                            d.push({
                                total: e.data.total,
                                rows: e.data.list
                            });
                            return d[0]
                        }
                    }
                }
                d.push({
                    total: 0,
                    rows: new Array()
                });
                return d[0]
            } else {
                d.push({
                    total: 0,
                    rows: new Array()
                });
                return d[0]
            }
        }
    })
}
function openModel(a) {
    if (a != null && a != "" && a != undefined) {
        $("#" + a).modal("toggle")
    }
}
function cleanFormData(a) {
    if (a != null && a != "" && a != undefined) {
        document.getElementById("" + a).reset()
    }
}
function saveOrUpdateData(d, a, c, b) {
    $.ajax({
        url: a,
        type: "post",
        data: $("#" + c).serialize(),
        success: function (e) {
            if (e.success) {
                Shadow.success(e.message);
                if (d != null && d != "" && d != undefined) {
                    $("#" + d).modal("toggle")
                }
                if (b != null && b != "" && b != undefined) {
                    refreshTable(b)
                }
            } else {
                Shadow.error(e.message)
            }
        },
        error: function (e) {
            Shadow.error("异常错误,请刷新重试")
        }
    })
}
function layerConfim(a) {
    layer.confirm("确认执行该操作么？", {
        btn: ["确认[Y]", "取消[N]"]
    }, function () {
        a()
    }, function () {
        Shadow.info("操作取消");
        layer.close(layer.index)
    })
}
function deleteData(b, a) {
    $.ajax({
        url: b,
        type: "post",
        data: {
            "pk": a
        },
        success: function (c) {
            Shadow.success(c.message);
            layer.close(layer.index)
        },
        error: function (c) {
            Shadow.error("异常错误,请刷新重试");
            layer.close(layer.index)
        }
    })
}
function saveOrUpdateDataGet(c, a, b) {
    $.ajax({
        url: a,
        type: "get",
        success: function (d) {
            if (d.success) {
                Shadow.success(d.message);
                if (b != null && b != "" && b != undefined) {
                    if (c != null && c != "" && c != undefined) {
                        $("#" + c).modal("toggle")
                    }
                    if (b != null && b != "" && b != undefined) {
                        refreshTable(b)
                    }
                }
            } else {
                Shadow.error(d.message)
            }
        },
        error: function (d) {
            Shadow.error("异常错误,请刷新重试")
        }
    })
}
function initValidationForm(b, c, a) {
    $(function () {
        $("#" + b).Validform({
            btnSubmit: "#" + c,
            tiptype: 2,
            ignoreHidden: true,
            dragonfly: false,
            tipSweep: true,
            showAllError: true,
            postonce: false,
            ajaxPost: false,
            beforeSubmit: function () {
                if (a != null && a != "" && a != undefined) {
                    a()
                }
            },
            callback: function (d) {
                return false
            }
        })
    })
}
function refreshTable(a) {
    $("#" + a).bootstrapTable("refresh")
}
function getSingleSelection(c, d) {
    var a = $("#" + c).bootstrapTable("getSelections");
    if (a != null && a != "" && a != undefined) {
        var b = a[0];
        if (b != null && b != "" && b != undefined) {
            if (d != null && d != "" && d != undefined) {
                return a[0].getFileId
            } else {
                return a[0]
            }
        }
    } else {
        return null
    }
}
function getMutilSelections(d, e) {
    var c = $("#" + d).bootstrapTable("getSelections");
    if (c != null && c != "" && c != undefined) {
        if (c.length > 1) {
            if (e != null && e != "" && e != undefined) {
                var b = "";
                for (var a = 0; a < c.length; a++) {
                    if (a != c.length - 1) {
                        b += c[a].getFileId + ","
                    } else {
                        b += c[a].getFileId
                    }
                }
                return b
            } else {
                return c
            }
        }
    } else {
        return null
    }
}
function queryDeptTree(c, a, d) {
    var b = {
        view: {
            dblClickExpand: false,
            showLine: true
        },
        data: {
            simpleData: {
                enable: true
            }
        },
        callback: {
            onClick: d
        }
    };
    $.ajax({
        url: a,
        type: "POST",
        dataType: "json",
        success: function (f) {
            var e = $.fn.zTree.init($("#" + c), b, f);
            e.expandAll(true)
        }
    })
}
function refreshPage() {
    window.location.reload()
}
$.fn.serializeJsonObject = function () {
    var a = {};
    var b = this.serializeArray();
    $.each(b, function () {
        if (a[this.name]) {
            if (!a[this.name].push) {
                a[this.name] = [a[this.name]]
            }
            a[this.name].push()
        } else {
            a[this.name] = this.value || ""
        }
    });
    return a
};

function getUserRoleMenu(e) {
    var d = [];
    var c = $(".permission");
    if (c != null && c.length > 0) {
        if (e != null && e != "" && e != undefined) {
            d = e.split(",");
            if (d != null && d.length > 0) {
                for (var b = 0; b < c.length; b++) {
                    var a = $.inArray(c[b].id, d);
                    if (a != -1) {
                        $("#" + c[b].id).removeAttr("disabled")
                    }
                }
            }
        }
    }
}
function contrlMenuShowOrNot(e) {
    var d = [];
    var c = $(".sysmenu");
    if (c != null && c.length > 0) {
        if (e != null && e != "" && e != undefined) {
            d = e.split(",");
            if (d != null && d.length > 0) {
                for (var b = 0; b < c.length; b++) {
                    var a = $.inArray(c[b].id, d);
                    if (a >= 0) {
                        $("#" + c[b].id).css("display", "block")
                    }
                }
            }
        }
    }
}
function prepareSelectInfo(c, a, b) {
    $.ajax({
        url: a,
        type: "get",
        dataType: "json",
        success: function (f) {
            $("#" + c).empty();
            if (f != null) {
                var e = '<option value="">请选择</option>';
                for (var d = 0; d < f.length; d++) {
                    if (b != null && b != "" && b != undefined) {
                        if (f[d].pk == b) {
                            e += "<option value='" + f[d].pk + "' selected='selected'>" + f[d].userName + "</option>"
                        } else {
                            e += "<option value='" + f[d].pk + "'>" + f[d].userName + "</option>"
                        }
                    } else {
                        e += "<option value='" + f[d].pk + "'>" + f[d].userName + "</option>"
                    }
                }
                $("#" + c).append(e)
            }
        }
    })
}
function initWebScoket(b, c) {
    if (b != null && b != "" && b != undefined) {
        c = (c != null && c != "" && c != undefined) ? c : "nologin";
        var b = "ws://" + b + "/websocket/" + c;
        var a;
        if (typeof(WebSocket) == "undefined") {
            readMessage(true, "The Current Browser do not Support WebScoket communication. Please replace and try")
        } else {
            a = new WebSocket(b.replace("http", "ws"));
            a.onopen = function () {};
            a.onmessage = function (d) {
                readMessage(true, d.data)
            };
            a.onclose = function () {
                readMessage(true, "WebScoket Communication Closed")
            };
            a.onerror = function () {
                readMessage(false, "WebScoket Abnormal Interruption Of Communication")
            }
        }
    }
}
function readMessage(a, b) {
    toastr.options = {
        closeButton: true,
        debug: false,
        progressBar: true,
        positionClass: "toast-top-right",
        onclick: null,
        showDuration: "300",
        hideDuration: "1000",
        timeOut: "-1",
        extendedTimeOut: "-1",
        showEasing: "swing",
        hideEasing: "linear",
        showMethod: "fadeIn",
        hideMethod: "fadeOut"
    };
    if (a) {
        toastr.info(b)
    }
}
function ajaxFileUpload(c, a, b, f) {
    var d = document.getElementById("" + c).files[0];
    var e = new FormData();
    e.append("file", d);
    e.append("params", f);
    $.ajax({
        data: e,
        type: "POST",
        url: "/upload/imgUpload",
        cache: false,
        contentType: false,
        processData: false,
        dataType: "json",
        success: function (g) {
            if (g.success) {
                parent.layer.msg("图片上传成功!");
                if (a != null && a != "" && a != undefined) {
                    $("#" + a).attr("src", g.data[0])
                }
                if (b != null && b != "" && b != undefined) {
                    $("#" + b).val(g.data[0])
                }
            } else {
                parent.layer.msg(g.message)
            }
        },
        error: function (h, g) {
            parent.layer.msg("文件上传失败")
        }
    })
}
function isNotBlank(a) {
    if (a != null && a != "" && a != undefined) {
        return true
    }
    return false
}
function isBlank(a) {
    if (a != null && a != "" && a != undefined) {
        return false
    }
    return true
}
function loginout() {
    $.ajax({
        url: "/user/loginout",
        type: "POST",
        success: function (a) {
            if (a.code == "200") {
                window.location.href = "/back/login";
                return
            }
        },
        error: function () {
            layer.msg("系统登出失败")
        }
    })
}
function getNowFormatDate() {
    var b = new Date();
    var a = "-";
    var e = b.getFullYear();
    var f = b.getMonth() + 1;
    var d = b.getDate();
    if (f >= 1 && f <= 9) {
        f = "0" + f
    }
    if (d >= 0 && d <= 9) {
        d = "0" + d
    }
    var c = e + a + f + a + d;
    return c
}
function getNowYear() {
    var a = new Date();
    var b = a.getFullYear();
    return b
}
function getNowMouth() {
    var a = new Date();
    var b = a.getMonth() + 1;
    if (b >= 1 && b <= 9) {
        b = "0" + b
    }
    return b
}
function toDecimal(a) {
    var b = parseFloat(a);
    if (isNaN(b)) {
        return
    }
    b = Math.round(a * 100) / 100;
    return b
};